﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Web.UI.WebControls;
using FS.Business;
using FS.Common.DotNetCode;
using FS.Common.DotNetUI;
using FS.Web.UserControl;
using FS.Common.DotNetData;
using FS.Common.DotNetBean;
using FS.Common.DotNetEncrypt;
using FS.DataBase;
using System.Collections;
using System.Linq;
using System.Data.SqlClient;
using System.Data.Common;
using System.Web.SessionState;
using System.Web;

//未送签资料
namespace FS.Web.BLL.Visa_Base
{
    public partial class shi_Visa_Info1 : System.Web.UI.Page, IReadOnlySessionState
    {
        visa_dao _visa = new visa_dao();
        protected void Page_Load(object sender, EventArgs e)
        {
            this.PageControl1.pageHandler += new EventHandler(this.pager_PageChanged);
            if (!base.IsPostBack)
            {
                GetSelect_TrustInfo();
                initBase_City();
            }
        }

        protected void pager_PageChanged(object sender, EventArgs e)
        {
            this.DataBindGrid();
        }
        protected void lbtSearch_Click(object sender, EventArgs e)
        {
            this.Hchange.Value = "1"; 
            DataBindGrid();
        }

        private void GetSelect_TrustInfo()
        {
            DataTable dt = _visa.GetSelect_TrustInfo();
            ControlBindHelper.BindHtmlSelect(dt, this.trust_id, "trust_name", "trust_id", "请选择");
        }

        protected void ddlp_city_SelectedIndexChanged(object sender, EventArgs e)
        {
            string ls_city = this.ddlp_city.SelectedValue;
            DataTable dt = _visa.GetSelect_CertTypeInfoByCityID(ls_city);
            ControlBindHelper.BindDropDownList(dt, this.ddlp_type, "name", "id", "请选择");
        }
        //所属国家
        private void initBase_City()
        {
            DataTable dt = _visa.GetSelect_CityInfo();
            ControlBindHelper.BindDropDownList(dt, this.ddlp_city, "city_name", "city_id", "请选择");
        }

        private void DataBindGrid()
        {
            string sql = "";
            int count = 0;
            if (this.Hchange.Value == "1")
            {
                this.PageControl1.PageIndex = 1;
                this.Hchange.Value = "0";
            }
            if (this.S_info_getdate.Value != "" & this.E_info_getdate.Value != "")
            {
                sql = " and  Visa_Info.info_getdate between '" + this.S_info_getdate.Value + "' and '" + this.E_info_getdate.Value + "'";
            }
            if (this.Supply_Name.Value != "")
            {
                sql = sql  + " and Base_supply.Supply_Name like '%" + this.Supply_Name.Value + "%'";
                
            }
            if (this.ddlp_city.Text != "")
            {
                sql = sql + " and Visa_InfoDetail.City_id='" + this.ddlp_city.Text + "'";
               
            }
            if (this.ddlp_type.Text != "")
            {
                sql = sql + " and Visa_InfoDetail.Ref_CertType='" + this.ddlp_type.Text + "'";
                
            }
            if (this.InfoDetail_user.Value != "")
            {
                sql = sql + " and visa_infodetail.InfoDetail_user like '%" + this.InfoDetail_user.Value + "%'";
                
            }
            if (this.InfoDetail_userphone.Value != "")
            {
                sql = sql + " and Visa_Infodetail.InfoDetail_userphone like '%" + this.InfoDetail_userphone.Value + "%'";
               
            }
            if (this.InfoDetail_cardno.Value != "")
            {
                sql = sql + " and Visa_Infodetail.[InfoDetail_cardno] like '%" + this.InfoDetail_cardno.Value + "%'";
                
            }
            if (this.trust_id.Value != "")
            {
                sql = sql + " and visa_info.trust_id like '%" + this.trust_id.Value + "%'";
            }
            if (this.InfoDetail_operationname.Value != "")
            {
                sql = sql + " and Visa_Infodetail.[InfoDetail_operationname] like '%" + this.InfoDetail_operationname.Value + "%'";
                
            }
            //sql = "" + sql;
            StringBuilder sqls = new StringBuilder();
            IList<SqlParam> IList_param = new List<SqlParam>();
            sqls.Append(sql);
            DataTable dt = _visa.shi_GetVisaInfoPage(sqls, IList_param, this.PageControl1.PageIndex, this.PageControl1.PageSize, ref count);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i][11].ToString().ToLower() == "sendto")
                {
                    dt.Rows[i][11] = "送签";
                }
                if (dt.Rows[i][11].ToString().ToLower() == "post")
                {
                    dt.Rows[i][11] = "寄件";
                }
                if (dt.Rows[i][11].ToString().ToLower() == "audit")
                {
                    dt.Rows[i][11] = "审核";
                }
                if (dt.Rows[i][11].ToString().ToLower() == "resultok")
                {
                    dt.Rows[i][11] = "出签";
                }
                if (dt.Rows[i][11].ToString().ToLower() == "resultfalse")
                {
                    dt.Rows[i][11] = "拒签";
                }
                if (dt.Rows[i][11].ToString().ToLower() == "raise")
                {
                    dt.Rows[i][11] = "录证";
                }
                if (dt.Rows[i][8].ToString() == "1a")
                {
                    dt.Rows[i][8] = "是";
                }
                else
                {
                    dt.Rows[i][8] = "否";
                }
            }
            //ResultOK” then ‘出签ResultFalse” then ‘拒签'
            ControlBindHelper.BindRepeaterList(dt, this.rp_Item);
            this.PageControl1.SetPageCount(count);    
        }

        protected void lbtExport_Click(object sender, EventArgs e)
        {
            Response.Clear(); 
            Response.Buffer = true;
            Response.ContentType = "application/vnd.ms-excel.numberformat:@"; 
            this.EnableViewState = false; 
            Response.Charset = "UTF-8"; 
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");         
            Response.AppendHeader("Content-Disposition", "attachment;filename=" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".xls");                  
            Response.Write(printHid.Value);        
            Response.End();   
        }

    }
   
}